import axios from 'axios';
import { requestBegin, requestEnd } from './actionCommon';
import { shelvesUrl } from '../config/httpConfig';
// export const GET_SHELVES = 'GET_SHELVES';
export const SHELVES_RECEIVED = 'SHELVES_RECEIVED';
export const SHELVES_INIT = 'SHELVES_INIT';
axios.defaults.withCredentials = true;
export function getShelves (option) {
    return (dispatch) => {
        dispatch(requestBegin('isFetching'));
        return axios.get(shelvesUrl, {
            params: option.query,
        })
            .then((res) => {
                dispatch(shelfReceived({
                    list: res.data,
                }));
                dispatch(requestEnd('success'));
            })
            .catch(err => {
                if (err) {
                    dispatch(requestEnd('err'));
                }
            });
    };
}
export function shelfReceived (data) {
    return {
        type: SHELVES_RECEIVED,
        shelves: data.list,
    };
}
export function shelvesInit (data) {
    return {
        type: SHELVES_INIT,
        shelves: data,
    };
}
